const express   = require('express');
const expStatic = require('express-static');
const bodyparser = require('body-parser');

var server = express();
// 用户库
var users ={
	'heykui' : '123456',
	'smallcat': '234567',
	'lili' : '001'
}

// 接受POST
server.use(bodyparser.urlencoded({}))
server.use('/reg',function (req,res) {
	console.log(req.body);
	res.send(req.body);
	res.end()
});
// 接受GET
server.get('/login',function (req,res) {
	var user = req.query['user'];
	var pass = req.query['pass'];

	if (users[user]==null) res.send({ok:false,msg:"no User"});
	else {
		if (users[user]==pass) res.send({ok:true,msg:"login"});
		else res.send({ok:false,msg:"pass Error"});
	}
	res.end();
});

// 静态文件
server.use(expStatic('./www'));

server.listen(8080);
console.log("server is OK");